package com.aaa.controller;

import com.aaa.entity.F_order;
import com.aaa.entity.F_orderp;
import com.aaa.entity.F_returns;
import com.aaa.entity.Inventory;
import com.aaa.service.ForderServiceDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("forder")
public class Fordercontroller {
    @Resource
    ForderServiceDao forderserviceDao;

    @RequestMapping("find")
    @ResponseBody
    public List<F_order> find(Integer pagenum, Integer pagesize, Integer parcelid){
        Integer a=(pagenum-1)*pagesize;
        System.out.println(a);
        return forderserviceDao.find(a, pagesize, parcelid);
    }


    @RequestMapping("add")
    @ResponseBody
    public int add(F_order f_order){
        return  forderserviceDao.add(f_order);
    }

    @ResponseBody
    @RequestMapping("delete")
   public  int delete(Integer id){
        return  forderserviceDao.delete(id);
   }

   @RequestMapping("deliver")
   @ResponseBody
   public  int deliver(Integer id){
        return  forderserviceDao.deliver(id);
   }

   @ResponseBody
   @RequestMapping("take")
   public  int take(Integer id){
        return  forderserviceDao.take(id);
   }


    @ResponseBody
    @RequestMapping("findpage")
    public Map<String, Object> userList(Integer pageSize, Integer pageNum) {
        Map<String, Object> map = new HashMap<>();
        List<F_order> userList = forderserviceDao.findpage(pageSize, pageNum * pageSize);
        Integer TotalNum = forderserviceDao.findpagecount();

        map.put("userList", userList);
        map.put("TotalNum", TotalNum);
        return map;
    }

    @ResponseBody
    @RequestMapping("salesreturn")
    public Integer salesreturn(Integer id){
        return forderserviceDao.salesreturn(id);
    }


    @ResponseBody
    @RequestMapping("findpage1")
    public List<F_order> find1(){
        return forderserviceDao.findpage1();
    }

    @ResponseBody
    @RequestMapping("findpage2")
    public Map<String, Object> userList2(Integer pageSize, Integer pageNum) {
        Map<String, Object> map = new HashMap<>();
        List<F_order> userList = forderserviceDao.findpage2(pageSize, pageNum * pageSize);
        Integer TotalNum = forderserviceDao.findcount2();

        map.put("userList", userList);
        map.put("TotalNum", TotalNum);
        return map;
    }

    @RequestMapping("select")
    @ResponseBody
    public List<F_order> select(){
        return forderserviceDao.select();
    }

    @ResponseBody
    @RequestMapping("upd")
    public Integer upd(Integer id){
        return forderserviceDao.upd(id);
    }
    @ResponseBody
    @RequestMapping("updatenum")
    public Integer updatenum(F_orderp f_orderp){
        Inventory inventory=new Inventory();
        inventory.setSurplus(f_orderp.getNum());
        inventory.setBook(f_orderp.getBook());
        return forderserviceDao.updatenum(inventory);
    }


    @ResponseBody
    @RequestMapping("returnpage")
    public Map<String, Object> returnpage(Integer pageSize, Integer pageNum) {
        Map<String, Object> map = new HashMap<>();
        List<F_returns> userList = forderserviceDao.findreturn(pageSize, pageNum * pageSize);
        Integer TotalNum = forderserviceDao.returncount();
        map.put("userList", userList);
        map.put("TotalNum", TotalNum);
        return map;
    }


    @RequestMapping("returnupd")
    @ResponseBody
    public Integer returnupd(Integer user,Integer id){
        return forderserviceDao.returnupd(user, id);
    }

    @RequestMapping("findreturns")
    @ResponseBody
    public List<F_returns> findreturns(){
        return forderserviceDao.findreturns();
    }

}
